package com.hn.shopadmin.service.impl;

import com.hn.kiss.modules.sys.shopdb.entity.RoleMenu;
import com.hn.kiss.modules.sys.shopdb.entity.RoleMenuExample;
import com.hn.shopadmin.dao.RoleMenuDao;
import com.hn.shopadmin.dto.RoleMenuDTO;
import com.hn.shopadmin.service.RoleMenuService;
import com.hn.kiss.modules.sys.shopdb.mapper.RoleMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleMenuServiceimpl implements RoleMenuService {
    @Autowired
    RoleMenuMapper roleMenuMapper;
    @Autowired
    RoleMenuDao roleMenuDao;

    @Override
    public int add(String roleId, String[] menuIds) {
        int count = 0;
        //先删除
        del(roleId);

        RoleMenu roleMenu = new RoleMenu();
        roleMenu.setRoleId(roleId);
        for (String menuId : menuIds) {
            roleMenu.setMenuId(menuId);
            count += roleMenuMapper.insert(roleMenu);
        }

        return count;
    }

    @Override
    public int del(String roleId) {
        RoleMenuExample roleMenuExample = new RoleMenuExample();
        roleMenuExample.createCriteria().andRoleIdEqualTo(roleId);
        return roleMenuMapper.deleteByExample(roleMenuExample);
    }

    @Override
    public List<RoleMenuDTO> allMenuVsRole(String roleId) {
        return roleMenuDao.allMenuVsRole(roleId);
    }
}
